from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QSpinBox
 
class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
 
    def initUI(self):
        print("hello")
        self.layout = QVBoxLayout(self)
        self.spinBox = QSpinBox(self)
        self.spinBox.setMaximum(0)
        self.spinBox.valueChanged.connect(self.checkValue)
        self.layout.addWidget(self.spinBox)
 
    def checkValue(self, value):
        print(f"{value}")
        if value < 0 or value > 10:  # 检查值是否在范围外
            print("值超出范围，已重置为10")  # 输出警告或重置值
            self.spinBox.setValue(10)  # 重置为最大允许值
 
if __name__ == '__main__':
    app = QApplication([])
    ex = Example()
    ex.show()
    app.exec_()
